package org.dce.screencapturer.actions.ui;

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;

import org.dce.screencapturer.UI;
import org.dce.screencapturer.actions.ScreenCapturerAction;
import org.dce.screencapturer.util.IconFactory;

@SuppressWarnings("serial")
public class CaptureScreenshotAction 
	extends ScreenCapturerAction {

	public CaptureScreenshotAction() {
		super("categories.file", "actions.capture",IconFactory.getIcon("/images/capture.png"));
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		UI ui = getUI();
		
		try {
			Robot robot = new Robot();

			if (ui.isVisible()){
				ui.hideUI();
				Thread.sleep(1000);
			}
			
			Rectangle rect = new Rectangle();
			
			rect.setLocation(0,0);
			rect.setSize(Toolkit.getDefaultToolkit().getScreenSize());
			
			ui.addImageAsDrawing(robot.createScreenCapture(rect));
			
			ui.showUI();

		}catch (Exception ex){
			ex.printStackTrace();
		}
	}

}
